package main

// 类型推断：
// 将接口还原为具体类型，或判断是否实现了某个更具体的接口类型

import "fmt"

func main() {
	var a int64 = 3
	var i interface{} = a
	v1, ok := i.(int64) // 类型推断
	fmt.Printf("v1=%d, the type of v1 is %T, ok=%t\n", v1, v1, ok)

	v2, ok := i.(string) // 断言失败， v1 的类型是 string， 值是该类型的零值
	fmt.Printf("v2=%s, the type of v2 is %T, ok=%t\n", v2, v2, ok)

	v3 := i.(int64) // 断言成功
	fmt.Printf("v3=%d, the type of v3 is %T\n", v3, v3)

	v4 := i.(string) // 断言失败，抛出 panic
	fmt.Printf("v4=%s, the type of v4 is %T\n", v4, v4)
}
